#include <chrono>
#include <iostream>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include "yolov3_clip_detector.h"
#include "opencv2/opencv.hpp"

int main()
{
    const char * g_omModelPath = "../model/clipvitb32_224_5out.om";
    Yolov3CLIPDetector sampleProcess;
    bool ret = sampleProcess.init(g_omModelPath);
    if (!ret) {
        std::cout<<"sample init resource failed"<<std::endl;
        return 0;
    }

    std::vector<std::string> imageLists;
    float timeSum = 0;
    for (int i=1; i<3; i++){
        std::string imgpath = "../data/" + std::to_string(i) + ".jpg";
        imageLists.push_back(imgpath);
    }
    
    std::vector<message_result> results;
    std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
    for (int i=0;i<100; i++){
        results = sampleProcess.inference(imageLists);
    }
    std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double, std::milli> time_span = t2 - t1;
    std::cout<<"average time: "<<time_span.count()/100<<std::endl;
	
    for(auto data: results){
        std::cout<<"filename: "<<data.filenames[0]<<std::endl;
        std::vector<float> detectData = data.finalOutput[0];
        for(int i=0; i<6; i++){
            std::cout<<detectData[i]<<" ";
        }
        std::cout<<" "<<std::endl;
    }

    // std::vector<std::string> imageLists;
    // float timeSum = 0;
    // for (int i=0; i<100; i++){
    //     imageLists.push_back("../data/1.jpg");
    // }

    // std::vector<message_result> results = sampleProcess.inference(imageLists);
    // std::cout<<"epoch 0 end"<<std::endl;
    // imageLists.clear();
    // for (int i=0; i<100; i++){
    //     imageLists.push_back("../data/1.jpg");
    // }

    // std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
    // results = sampleProcess.inference(imageLists);
    // std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
    // std::chrono::duration<double, std::milli> time_span = t2 - t1;
	// timeSum += time_span.count();
    // std::cout<<"epoch 1 end"<<std::endl;

    // for(auto data: results){
    //     std::cout<<"filename: "<<data.filename_visible<<std::endl;
    //     float* detectData = data.finalOutput[0];
    //     for(int i=0; i<6; i++){
    //         std::cout<<detectData[i]<<std::endl;
    //     }
    // }
    // std::cout << "It took " << time_span.count() << " milliseconds."<<std::endl;
    // std::cout<<"average time: "<<timeSum/100<<std::endl;
    // std::cout<<"execute sample success"<<std::endl;
    return 1;
}



